﻿using System;
using System.Collections;
using System.Text;

namespace iPdf
{
    static class TaskQueue
    {
        private static Queue queue;
        private static bool justQueued = false;

        public static bool JustQueued
        {
            get
            {
                return justQueued;
            }
            set
            {
                justQueued = value;
            }
        }

        static TaskQueue()
        {
            queue = new Queue();
        }

        public static void AddTask(Task task)
        {
            if (task != null)
            {
                lock (queue.SyncRoot)
                {
                    queue.Enqueue(task);
                    justQueued = true;
                }
            }
        }

        public static Task GetTask()
        {
            if (queue.Count != 0)
            {

                lock (queue.SyncRoot)
                {
                    if (queue.Count == 1)
                    {
                        justQueued = false;
                    }
                    return (Task)queue.Dequeue();
                }

            }
            return null;
        }
    }
}
